﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Freeform;

namespace Space_in_Shaders
{
    public class NMotion : MotionController
    {
        public Vector2 Force { get; set; }
        public Single ForceResistance { get; set; }
        public Vector2 Velocity { get; set; }
        public Single Torque { get; set; }
        public Single TorqueResistance { get; set; }
        public Single Spin { get; set; }
        public Single Mass { get; set; }
        public Single MoI { get; set; }
        public Single Thrust { get; set; }

        public NMotion(SpatialProperties s)
            :base (s)
        {
            Mass = 1;
            MoI = 1;
            ForceResistance = 0.99f;
            TorqueResistance = 0.99f;
        }

        public override void Update(GameTime time)
        {
            base.Update(time);

            Vector2 Acceleration = Force / Mass;
            Velocity += Acceleration * time.ElapsedGameTime.Milliseconds / 1000f;
            Velocity *= ForceResistance;
            SpatialProperties.Position += Velocity * time.ElapsedGameTime.Milliseconds / 1000f;

            Single AngularAccel = Torque / Mass;
            Spin += AngularAccel * time.ElapsedGameTime.Milliseconds / 1000f;
            Spin *= TorqueResistance;
            SpatialProperties.Direction += Spin * time.ElapsedGameTime.Milliseconds / 1000f;

            Force = Vector2.Zero;
            Torque = 0;
        }
        public void ApplyForce(Vector2 t) { Force += t; }
        public void ApplyTorque(Single t) { Torque += t; }
    }
}
